package br.com.pd.invocation;

import java.util.ArrayList;
import java.util.List;

import br.com.util.PropertiesLoader;

public class InvokerInfo {
	
	private String code;
	private String message;
	private long timeOut;
	private long criationTime;
	private int listenerQuantity;

	public InvokerInfo(String ip, int listenerQuantity, String message){
		this.code = ip + this.hashCode();
		this.criationTime = System.currentTimeMillis();
		this.listenerQuantity = listenerQuantity;
		this.message = message;
		this.timeOut = Integer.parseInt(PropertiesLoader.getInstance().getPropertie(PropertiesLoader.TIME_OUT_MESSAGE_INFO)); 
	}

	public String getCode() {
		return code;
	}


	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public long getTimeOut() {
		return timeOut;
	}

	public void setTimeOut(long timeOut) {
		this.timeOut = timeOut;
	}

	public void addResponse(){
		this.listenerQuantity--;
	}
	
	public boolean isComplete(){
		long now = System.currentTimeMillis();
		if ((this.listenerQuantity <= 0)) {
			System.out.println("listener <= 0");
		}
		if (((now - this.criationTime) >= this.timeOut)) {
			System.out.println("timeout estourado");
		}
		return (this.listenerQuantity <= 0) || ((now - this.criationTime) >= this.timeOut) ; 
	}
}
